package cn.tedu.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadPoolScheduledTests {
    public static void main(String[] args) {
        Executors.newScheduledThreadPool(5)
                .scheduleAtFixedRate(()->{//时间间隔：period
                    System.out.println("task1:"+System.currentTimeMillis());
                    try{Thread.sleep(1000);}catch (Exception e){}
                },0,1, TimeUnit.SECONDS);

        //多个任务执行时，延迟时间=任务执行时间+delay
        Executors.newScheduledThreadPool(5)
                .scheduleWithFixedDelay(()->{//时间间隔=任务执行时间+delay
                    System.out.println("task2:"+System.currentTimeMillis());
                    try{Thread.sleep(1000);}catch (Exception e){}
                },0,1, TimeUnit.SECONDS);
    }
}
